package cn.ywang.spring.framework.aop.framework.adapter;

import cn.ywang.spring.framework.aop.aspect.AbstractAspectAdvice;
import cn.ywang.spring.framework.aop.aspect.Advice;
import cn.ywang.spring.framework.aop.intercept.MethodInterceptor;
import cn.ywang.spring.framework.aop.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * @author BeatificWang
 * @date 2019/5/4 21:32
 */
public class AfterThrowingAdviceInterceptor extends AbstractAspectAdvice implements Advice, MethodInterceptor {

	/**
	 * Non-null if after throwing advice binds the thrown value
	 */
	private String throwingName;

	public AfterThrowingAdviceInterceptor(Method aspect, Object target) {
		super(aspect, target);
	}

	public void setThrowName(String throwingName) {
		this.throwingName = throwingName;
	}

	@Override
	public Object invoke(MethodInvocation mi) throws Throwable {
		try {
			return mi.proceed();
		} catch (Throwable ex) {
			this.invokeAdviceMethod(mi, null, ex);
			throw ex;
		}
	}
}


